package com.ruoyi.quanzi.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.quanzi.domain.SunCategory;
import com.ruoyi.quanzi.service.ISunCategoryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 圈子分类Controller
 * 
 * @author ruoyi
 * @date 2024-12-19
 */
@RestController
@RequestMapping("/system/category")
public class SunCategoryController extends BaseController
{
    @Autowired
    private ISunCategoryService sunCategoryService;

    /**
     * 查询圈子分类列表
     */
    @PreAuthorize("@ss.hasPermi('system:category:list')")
    @GetMapping("/list")
    public TableDataInfo list(SunCategory sunCategory)
    {
        startPage();
        List<SunCategory> list = sunCategoryService.selectSunCategoryList(sunCategory);
        return getDataTable(list);
    }

    /**
     * 查询热门圈子列表
     */
    @GetMapping("/hot")
    public AjaxResult hot()
    {
        List<SunCategory> list = sunCategoryService.selectHotCategories();
        return AjaxResult.success(list);
    }

    /**
     * 查询推荐圈子列表
     */
    @GetMapping("/recommend")
    public AjaxResult recommend()
    {
        List<SunCategory> list = sunCategoryService.selectRecommendCategories();
        return AjaxResult.success(list);
    }

    /**
     * 导出圈子分类列表
     */
    @PreAuthorize("@ss.hasPermi('system:category:export')")
    @Log(title = "圈子分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SunCategory sunCategory)
    {
        List<SunCategory> list = sunCategoryService.selectSunCategoryList(sunCategory);
        ExcelUtil<SunCategory> util = new ExcelUtil<SunCategory>(SunCategory.class);
        util.exportExcel(response, list, "圈子分类数据");
    }

    /**
     * 获取圈子分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:category:query')")
    @GetMapping(value = "/{cateId}")
    public AjaxResult getInfo(@PathVariable("cateId") Long cateId)
    {
        return AjaxResult.success(sunCategoryService.selectSunCategoryById(cateId));
    }

    /**
     * 新增圈子分类
     */
    @PreAuthorize("@ss.hasPermi('system:category:add')")
    @Log(title = "圈子分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SunCategory sunCategory)
    {
        return toAjax(sunCategoryService.insertSunCategory(sunCategory));
    }

    /**
     * 修改圈子分类
     */
    @PreAuthorize("@ss.hasPermi('system:category:edit')")
    @Log(title = "圈子分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SunCategory sunCategory)
    {
        return toAjax(sunCategoryService.updateSunCategory(sunCategory));
    }

    /**
     * 删除圈子分类
     */
    @PreAuthorize("@ss.hasPermi('system:category:remove')")
    @Log(title = "圈子分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cateIds}")
    public AjaxResult remove(@PathVariable Long[] cateIds)
    {
        return toAjax(sunCategoryService.deleteSunCategoryByIds(cateIds));
    }

    /**
     * 修改圈子分类状态
     */
    @PreAuthorize("@ss.hasPermi('system:category:edit')")
    @Log(title = "圈子分类状态", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody SunCategory sunCategory)
    {
        return toAjax(sunCategoryService.updateSunCategory(sunCategory));
    }
}